﻿using CPPEI.Coolzon.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace CPPEI.Coolzon.Designer.Views
{
    public static class RemovePartCommand
    {
        public static void Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Part selectedPart = UIContext.Current.CurrentDesignView.API_GetSelectedPart();
            if(selectedPart is AreaPart && selectedPart.ParentPart is ScenePart && (selectedPart.ParentPart as ScenePart).SceneMatadata.IsAllowSwapArea)
            {
                AreasInSceneRemoveOperation operation = new AreasInSceneRemoveOperation(UIContext.Current.CurrentDesignView, selectedPart.ParentPart as ScenePart, selectedPart as AreaPart);
                OperationCenter.Instance.Do(operation);
            }
            else
            {
                RemovePartOperation operation = new RemovePartOperation(UIContext.Current.CurrentDesignView, UIContext.Current.CurrentDesignView.API_GetSelectedPart());
                OperationCenter.Instance.Do(operation);
            }
        }
        public static void CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (UIContext.Current.CurrentDesignView != null && UIContext.Current.CurrentDesignView.API_IsEditable())
            {
                Coolzon.UI.Part selectedPart = UIContext.Current.CurrentDesignView.API_GetSelectedPart();
                if (selectedPart != null && !(selectedPart is Coolzon.UI.ScenePart))
                {
                    e.CanExecute = true;
                }
                else
                {
                    e.CanExecute = false;
                }
            }
            else
            {
                e.CanExecute = false;
            }
        }
    }
}
